// pages/SL_SQ_Status/SL_SQ_Status.js
import request from "../../utils/request"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        objectArray:[
            
        ]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        console.log(wx.getStorageSync('Token')[0].Name)
        request({
            url:`/SQ?user=${wx.getStorageSync('Token')[0].Name}&SQstatus=0`,
            method:"GET",
        }).then(res=>{
            console.log(res)
            for(var i = 0;i < res.length;i++){
                var objectarray = 'objectArray['+i+']'
                this.setData({
                    [objectarray+'.id']:res[i].id,
                    [objectarray+'.SQname']:res[i].SQname,
                    [objectarray+'.SQtel']:res[i].SQtel,
                    [objectarray+'.SQcause']:res[i].SQcause,
                    [objectarray+'.SQtime']:res[i].SQtime,
                    [objectarray+'.SQstatus']:res[i].SQstatus,
                })
                console.log(this.data.objectArray[i])
            }
        })
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    Status_YES(event){
        //获取id
        console.log(event.currentTarget.id)
        var id = parseInt(event.currentTarget.id) 
        wx.setStorageSync('id', id)
        console.log("id = "+id)
        //开始操作数据库
        request({
            url:`/SQ?id=${id}`,
            method:"GET"
        }).then(res=>{
            console.log(res)
            request({
                url:`/SQ/${id}`,
                method:"put",
                data:{
                    unit:res[0].unit,
                    user:res[0].user,
                    SQcause:res[0].SQcause,
                    SQname:res[0].SQname,
                    SQtel:res[0].SQtel,
                    SQtime:res[0].SQtime,
                    id:res[0].id,
                    SQstatus:"1"
                },
            }).then(res=>{
                console.log(res)
                wx.navigateBack({
                  delta: 1,
                })
            })
        })
    },
    Status_NO(event){
        console.log(event.currentTarget.id)
        var id = parseInt(event.currentTarget.id) 
        console.log("id = "+id)
        request({
            url:`/SQ?id=${id}`,
            method:"GET"
        }).then(res=>{
            console.log(res)
            request({
                url:`/SQ/${id}`,
                method:"put",
                data:{
                    unit:res[0].unit,
                    user:res[0].user,
                    SQcause:res[0].SQcause,
                    SQname:res[0].SQname,
                    SQtel:res[0].SQtel,
                    SQtime:res[0].SQtime,
                    id:res[0].id,
                    SQstatus:"-1"
                },
            }).then(res=>{
                console.log(res)
                wx.navigateBack({
                  delta: 1,
                })
            })
        })
    }
})